package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.HealthEntity;
import com.ruoyi.web.dorm.service.DormHealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/dormHealth")
public class DormHealthController extends BaseController {

    @Autowired
    private DormHealthService dormHealthService;

    /**
     * 查询宿舍卫生信息
     * @param healthEntity
     * @return
     */
    @GetMapping("/getDormHealth")
    public TableDataInfo getDormHealth(HealthEntity healthEntity){
        startPage();
        return getDataTable(dormHealthService.getDormHealth(healthEntity));
    }

    /**
     * 添加宿舍卫生信息
     * @param healthEntity
     * @return
     */
    @PostMapping("/addDormHealth")
    public AjaxResult addDormHealth(@RequestBody HealthEntity healthEntity ){
        return toAjax(dormHealthService.addDormHealth(healthEntity));
    }

    /**
     * 更新宿舍卫生信息
     * @param healthEntity
     * @return
     */
    @PostMapping("/updateDormHealth")
    public AjaxResult updateDormHealth(@RequestBody HealthEntity healthEntity){
        return toAjax(dormHealthService.updateDormHealth(healthEntity));
    }

    /**
     * 假删除宿舍卫生信息
     * @param id
     * @return
     */
    @DeleteMapping("/delDormHealth")
    public AjaxResult delDormHealth(Long id){
        return toAjax(dormHealthService.delDormHealth(id));
    }



    /**
     * 查询宿舍卫生信息导出信息
     * @param healthEntity
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, HealthEntity healthEntity){
        List<HealthEntity> list = dormHealthService.getDormHealth(healthEntity);
        ExcelUtil<HealthEntity> util = new ExcelUtil<>(HealthEntity.class);
        util.exportExcel(response,list,"宿舍卫生信息数据");
    }



}
